package com.colabo.j2ee.web.core.common;

import java.util.Properties;

import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

public class PropertyPlaceholderConfigurerExt extends PropertyPlaceholderConfigurer {
	private static String PLACEHOLDER_DEFAULT_VALUE_SEPARATOR = "|";
	private String placeholderSeparator = PLACEHOLDER_DEFAULT_VALUE_SEPARATOR;

	public String getPlaceholderSeparator() {
		return placeholderSeparator;
	}

	public void setPlaceholderSeparator(String placeholderSeparator) {
		this.placeholderSeparator = placeholderSeparator;
	}

	protected String resolvePlaceholder(String placeholder, Properties props) {
		int separatorIndex = placeholder.indexOf(placeholderSeparator);
		if (separatorIndex == -1) {
			return super.resolvePlaceholder(placeholder, props);
		}
		String propKey = placeholder.substring(0, separatorIndex);
		String defPropVal = placeholder.substring(separatorIndex + 1);
		return props.getProperty(propKey, defPropVal);
	}

}